namespace UmSoft.SharePoint.Integration._1Cv77
{
    using System;
    using UmSoft.SharePoint.Integration._1Cv77;

    public class V7Reference : V7Object
    {
        private bool hierarchyMode;
        public V7Reference(V7Object obj) : base(obj)
        {
        }
        public override string ToString()
        {
            return this.InvokeMethod("Вид", new object[0]).ToString();
        }
        public bool Select()
        {
            return base.InvokeMethod("ВыбратьЭлементы",
                new object[] {
                        (this.hierarchyMode ? 1 : 0)}).Equals(V7.TRUE);
        }
        public bool SelectByRequisite(string requisiteName, string requisiteValue, bool hierarchyMode, bool groupMode)
        {
            return this.InvokeMethod("ВыбратьЭлементыПоРеквизиту", new object[] { requisiteName, requisiteValue, hierarchyMode ? 1 : 0, groupMode ? 1 : 0 }).Equals(V7.TRUE);

        }
        public bool FindByCode(string code)
        {
            return base.InvokeMethod("НайтиПоКоду",
                new object[] {
                        code}).Equals(V7.TRUE);
        }
        public bool FindByName(string name)
        {
            return this.FindByName(name, true, false);

        }
        public bool FindByName(string name, bool mode, bool isExactly)
        {
            return base.InvokeMethod("НайтиПоНаименованию",
                new object[] {
                        name,
                        (mode ? V7.TRUE : V7.FALSE),
                        (isExactly ? V7.TRUE : V7.FALSE)}).Equals(V7.TRUE);
        }
        public bool FindByRequisite(string requisiteName, string requisiteValue)
        {
              return this.InvokeMethod("НайтиПоРеквизиту", new object[] { requisiteName, requisiteValue, 1 }).Equals(V7.TRUE);
        }
        public bool FindElement(V7Object element)
        {
            return base.InvokeMethod("НайтиЭлемент",
                new object[] {
                        element.Object}).Equals(V7.TRUE);
        }
        public V7ReferenceElement New()
        {
            this.InvokeMethod("Новый", new object[0]);
            return this.Current;

        }
        public V7ReferenceElement NewGroup()
        {
            base.InvokeMethod("НоваяГруппа",
                new object[0]);
            return Current;
        }
        public V7ReferenceElement GetItem()
        {
            if (this.InvokeMethod("ПолучитьЭлемент", new object[0]).Equals(V7.TRUE))
            {
                return this.Current;
            }
            return null;

        }
        public DateTime SetDate(DateTime date, bool setNow)
        {
            return Convert.ToDateTime(base.InvokeMethod("ИспользоватьДату",
                    new object[] {
                            date,
                            (setNow ? 1 : 0)}));
        }
        public V7ReferenceElement SetOwner(V7Object newOwner)
        {
            V7Object obj2 = this.InvokeMethod("ИспользоватьВладельца", new object[] { newOwner.Object }) as V7Object;
            if (obj2 == null)
            {
                return null;
            }
            this.hierarchyMode = newOwner != null;
            return new V7ReferenceElement(obj2, null);

        }
        public V7ReferenceElement SetParent(V7Object newParent)
        {
            V7Object v7Object;
            v7Object = base.InvokeMethod("ИспользоватьРодителя",
                new object[] {
                        newParent.Object}) as V7Object;
            if (v7Object != null)
            {
                return new V7ReferenceElement(v7Object, this);
            }
            else
            {
                return null;
            }
        }
        public virtual V7ReferenceElement Current
        {
            get
            {
                return new V7ReferenceElement(this.InvokeMethod("ТекущийЭлемент", new object[0]) as V7Object, this);

            }
        }
        public bool IsSelect
        {
            get
            {
                return base.InvokeMethod("Выбран",
                    new object[0]).Equals(V7.TRUE);
            }
        }
        public virtual V7ReferenceElement this[string code]
        {
            get
            {
                if (this.FindByCode(code))
                {
                    return this.Current;
                }
                return null;

            }
        }
    }
}
